﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using Indigo = System.IdentityModel.Selectors;

namespace Microsoft.Cryptography.WCF
{
    /// <summary>
    /// Custom X509SecurityTokenProivder is required to support RSA-Signatures with SHA-2 encryption in XML-Signatures
    /// </summary>
    public class X509SecurityTokenProvider : Indigo.X509SecurityTokenProvider
    {
        /// <summary>
        /// Custom X509SecurityTokenProivder is required to support RSA-Signatures with SHA-2 encryption in XML-Signatures
        /// </summary>
        /// <param name="cert">Certificate, which should be used as security token</param>
        public X509SecurityTokenProvider(X509Certificate2 cert)
            : base(cert)
        {
        }

        /// <summary>
        /// Custom X509SecurityTokenProivder is required to support RSA-Signatures with SHA-2 encryption in XML-Signatures
        /// </summary>
        /// <param name="location">Location of the certificate-store containing the certificate, which should be used as security token</param>
        /// <param name="name">Name of the certificate-store containing the certificate, which should be used as security token</param>
        /// <param name="findType">FindType to identify the certificate, which should be used as security token</param>
        /// <param name="findValue">Search pattern to identify the certificate, which should be used as security token</param>
        public X509SecurityTokenProvider(StoreLocation location, StoreName name, X509FindType findType, object findValue)
            : base(location, name, findType, findValue)
        {
        }

        /// <summary>
        /// Returns a custom X509SecurityToken instead of the <see cref="System.IdentityModel.Tokens.X509SecurityToken"/> to support
        /// RSA-Signatures with SHA-2 encryption in XML-Signatures
        /// </summary>
        /// <param name="timeout"></param>
        /// <returns></returns>
        protected override System.IdentityModel.Tokens.SecurityToken GetTokenCore(TimeSpan timeout)
        {
            return new X509SecurityToken(base.Certificate);
        }

        
    }
}


